<?php

class Core_Controller_Admincp_Form_Item_Index extends Nuo_Controller_Admincp
{
	function execute($request)
	{

		$id = $request -> getParam('form_id');

		if (!$id)
		{
			Nuo::redirect('admincp/core/form');
			exit ;
		}

		$form = Nuo::getTable('core/html/form') -> find($id) -> current();

		Nuo::setVar('breadcrum', array(
			'links' => array(
				'admincp' => 'AdminCP',
				'admincp/appearance' => 'Appearance',
				'admincp/core/form' => 'Nuo_Form',
			),
			'title' => 'Design Nuo_Form "' . $form -> getTitle() . '"',
			'toolbar'=>'admincp/form/item'
		
		));
		

		$table2 = Nuo::getTable('core/html/element');
		$table3 = Nuo::getTable('core/html/data');
		$table = Nuo::getTable('core/html/item');

		$select = $table -> select() 
		-> from(array('item' => $table -> getName()))
		-> joinLeft(array('ele' => $table2 -> getName()), 'ele.element_id=item.element_id','ele.element_title') 
		-> joinLeft(array('data' => $table3 -> getName()), 'data.data_id=item.data_id','data.data_title') 
		-> where('form_id=?', $id);
		
		$items = $table -> fetchAll($select);

		return  Nuo::getView()->render('core/view/controller/browse/admincp/form/item/index', array('items' => $items));
	}

}
